Imports System.Web
Imports System.Data
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.DBNull
Imports System.Data.SqlClient
Imports System.Runtime.InteropServices
Imports System.Configuration
Imports System.Web.HttpContext
Public Class adm_addmerchant
    Inherits System.Web.UI.Page
    Public helpaid As String = ""
    Dim objvalid As New gaValidation
    'Dim oAddmerch As gaMerchAccount.AdminMerchant
    Dim objdt As GetData = New GetData
    Public aUserSession(13) As String
    Protected WithEvents confirmpassword As System.Web.UI.WebControls.TextBox
    Public Msg, imgpath, currtURL As String
    Protected WithEvents GID As System.Web.UI.WebControls.DropDownList
    Protected WithEvents CompNM As System.Web.UI.WebControls.DropDownList
    Protected WithEvents CompLc As System.Web.UI.WebControls.DropDownList
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents MembType As System.Web.UI.WebControls.DropDownList
#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents btnCancel As System.Web.UI.WebControls.Button
    Protected WithEvents x As System.Web.UI.HtmlControls.HtmlForm
    Protected WithEvents btnCreate As System.Web.UI.WebControls.Button
    Protected WithEvents Address1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Address2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents City As System.Web.UI.WebControls.TextBox
    Protected WithEvents State As System.Web.UI.WebControls.TextBox
    Protected WithEvents ZIP As System.Web.UI.WebControls.TextBox
    Protected WithEvents Contact_Name As System.Web.UI.WebControls.TextBox
    Protected WithEvents Contact_Phone1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Contact_Phone2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Contact_Email As System.Web.UI.WebControls.TextBox
    Protected WithEvents MerchantURL As System.Web.UI.WebControls.TextBox
    Protected WithEvents Market As System.Web.UI.WebControls.DropDownList
    Protected WithEvents password As System.Web.UI.WebControls.TextBox

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            Msg = ""
            objValid.getURL(Request.Url.ToString, imgpath, currtURL)
            Builddropdows()
        Else
            Buildselcdropdows()
        End If

    End Sub
    Private Sub Buildselcdropdows()

    End Sub
    Private Sub Builddropdows()
        Dim Dr As SqlDataReader
        Dim strError As String = ""
        Dim i As Integer
        'oAddmerch = New gaMerchAccount.AdminMerchant
        'oAddmerch.DBConnectString = Application("DSN")
        Dim ssQL As String = ""
        ssQL = "SELECT u.GAPORTAL_ID,u.Company_name, u.Member_Type, u.country_code,c.Country_name from users u, country c "
        ssQL += "WHERE u.user_id <>'000000' and company_id =NULL "
        objdt.DBConnection = Application("DSN")
        Dr = objdt.DataReader(ssQL, strError)
        If Len(strError) = 0 Then
            i = 0
            GID.Items.Clear()
            GID.Items.Add(New ListItem("", ""))
            CompNM.Items.Clear()
            CompNM.Items.Add(New ListItem("", ""))

            MembType.Items.Clear()
            MembType.Items.Add(New ListItem("", ""))
            Do While Dr.Read()
                If Len(Dr.GetString(0)) > 0 Then
                    GID.Items.Add(New ListItem(Dr.GetInt32(0), CStr(Dr.GetInt32(0))))
                    CompNM.Items.Add(New ListItem(Dr.GetString(1), i)) ''.ToUpper = Trim(strCompName.ToUpper) Then
                    MembType.Items.Add(New ListItem(Dr.GetString(2), Dr.GetString(2)))
                    'CompLc.Items.Add(New ListItem(Dr.GetString(3), ""))
                    i = i + 1
                End If
            Loop
        Else
            Msg = strError
            Exit Sub
        End If

    End Sub
    Public Sub ShowSelectCountry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim url As String
        Dim ScriptStr As String
        Dim WindowProp As String
        WindowProp = """height=450px,width=305px,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes"""
        url = """countries.aspx"""
        ScriptStr = "<script language=javascript>window.open(" & url & ",null," & WindowProp & ",true) </script>"
        'Page.RegisterStartupScript("OpenReport", ScriptStr)
    End Sub

    Public Sub getURL(ByVal CurrtUrlstring As String, ByRef imgpath As String, ByRef strURL As String)
        'Private Function ReadURLPageName(ByVal strurl As String) As String
        Dim arrTemp As Array
        Dim intPageNamePos As Integer
        Dim imagefd As String = "images"
        Dim strTemp As String

        arrTemp = Split(CurrtUrlstring, "/")
        intPageNamePos = arrTemp.GetUpperBound(0)
        strTemp = arrTemp(intPageNamePos - 1)
        If strTemp.ToLower = "admin" Then
            imgpath = "/" & arrTemp(intPageNamePos - 2) & "/" & imagefd & ""
        End If

    End Sub
    Private Function validate_inputtxt(ByRef txtbox As TextBox, ByVal intTp As Integer) As String
        Dim strText As String = ""

        If Len(txtbox.Text) > 0 Then
            strText = txtbox.Text
            'arrParamer(intTp) = Trim(strText)
        Else
            Select Case intTp
                Case 1
                    Msg = "Please select a country"
                Case 3
                    Msg = "Please enter merchant address"
                Case 4
                    Msg = "Please enter a city"
                Case 5
                    Msg = "Please enter a zip code"
                Case 6
                    Msg = "Please enter contact name"
                Case 7
                    Msg = "Please enter contact phone number"

                Case 8
                    Msg = "Please enter merchant contact E-Mail"
            End Select

        End If
        If Len(strText) > 0 And Len(Msg) = 0 Then
            Return strText

        Else
            'msg = "Please complete all information."
            Return Msg
        End If

    End Function
    Private Function validate_dropbox(ByRef dropbox As DropDownList, ByVal intTp As Integer) As String
        Dim strValue As String = ""
        If dropbox.SelectedIndex > 0 Then
            strValue = dropbox.SelectedItem.Value
            'arrParamer(intTp) = strValue

        Else
            Select Case intTp
                Case 1
                    Msg = "Plese select a GAPortal ID."
                Case 2
                    Msg = "Please select a Company Name."
                Case 3
                    Msg = "Please select a member type."

            End Select

        End If

        If Len(strValue) > 0 And Len(Msg) = 0 Then

            Return strValue
        Else

            Return Msg
        End If
    End Function
    Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
        'oValidator = Server.CreateObject("viaFormValidator.General")

        'pwd1 = CheckString(Request("Password"))
        'pwd2 = CheckString(Request("confirmpassword"))
        'If Len(pwd1) <> 0 Then
        '    sPasswordValid = oValidator.general_checkpassword(CStr(pwd1), CStr(pwd2), oValidator.general_ONEALPHAONENUM, , 6, 15, "Password")
        '    If Len(sPasswordValid) Then Msg = sPasswordValid & "."
        'Else
        '    Msg = "Password is required."
        'End If

        'TID = safestring(Request.Form("TerminalNumber"))
        'If Len(TID) <> 0 Then
        '    sTermNumValid = oValidator.general_checklen(CStr(TID), 7, 22, "Terminal Number")
        '    If Len(sTermNumValid) = 0 Then
        '        sTermNumValid = oValidator.general_checkchartype(CStr(TID), oValidator.general_NUM, , "Terminal Number")
        '    End If
        '    If Len(sTermNumValid) Then Msg = sTermNumValid & "."
        'Else
        '    Msg = "Terminal Number is required."
        'End If

        'Email = CheckString(Request("MerchantEmail"))
        'If Len(Email) <> 0 Then
        '    ValidEmail = oValidator.general_checkemail(CStr(Email), "Terminal E-mail Address")
        '    If Len(ValidEmail) <> 0 Then
        '        Msg = ValidEmail & "."
        '    End If
        'End If

        'Email = CheckString(Request("Contact_Email"))
        'If Len(Email) <> 0 Then
        '    ValidEmail = oValidator.general_checkemail(CStr(Email), "Contact E-mail Address")
        '    If Len(ValidEmail) <> 0 Then
        '        Msg = ValidEmail & "."
        '    End If
        'Else
        '    Msg = "Contact E-mail Address is required. Please enter your Contact E-mail Address."
        'End If

        'oValidator = Nothing

        'If Request("MerchantType") <> "" Then
        '    MerchantType = Safestring(Request.Form("MerchantType"))
        'Else
        '    Msg = "Please select a merchant type"
        'End If

        'If Msg = "" Then
        '    On Error Resume Next
        '    oAddmerch = Server.CreateObject("viaMerchAccount.AdminMerchant")
        '    oAddmerch.DBConnectString = Application("DSN")
        '    If aUserSession(cCOMPANY_ID) = "0" Then
        '        oAddmerch.CompanyID = Request("CID")
        '    Else
        '        oAddmerch.CompanyID = Application("CompanyID")
        '    End If
        '    password = safestring(Request.Form("password"))
        '    MerchantType = Safestring(Request("MerchantType"))
        '    oAddmerch.SESSION_USER_ID = aUserSession(cUSER_ID)
        '    oAddmerch.SESSION_VIAKLIX_ID = aUserSession(cVIAKLIX_ID)
        '    oAddmerch.SESSION_COMPANY_ID = aUserSession(cCOMPANY_ID)
        '    oAddmerch.CompanyName = SafeString(Request("CompanyName"))
        '    oAddmerch.AccountName = SafeString(Request("AccountName"))
        '    oAddmerch.CompanyAlias = SafeString(Request("CompanyAlias"))
        '    oAddmerch.Address1 = SafeString(Request.Form("Address1"))
        '    oAddmerch.Address2 = SafeString(Request.Form("Address2"))
        '    oAddmerch.City = SafeString(Request.Form("City"))
        '    oAddmerch.State = SafeString(Request.Form("State"))
        '    oAddmerch.ZipCode = SafeString(Request.Form("Zip"))
        '    oAddmerch.Contact_Name = SafeString(Request.Form("Contact_Name"))
        '    oAddmerch.Contact_Phone1 = SafeString(Request.Form("Contact_Phone1"))
        '    oAddmerch.Contact_Phone2 = SafeString(Request.Form("Contact_Phone2"))
        '    oAddmerch.Contact_Email = SafeString(Request.Form("Contact_Email"))
        '    oAddmerch.TerminalNumber = SafeString(Request("TerminalNumber"))
        '    oAddmerch.MerchantURL = SafeString(Request.Form("MerchantURL"))
        '    oAddmerch.MerchantEmail = SafeString(Request.Form("MerchantEmail"))
        '    oAddmerch.market = safestring(Request.Form("Market"))
        '    '-----	BW 1/17/02 server ip, server time, and source ip auditing
        '    oAddmerch.ServerIP = safestring(Request.ServerVariables("LOCAL_ADDR"))
        '    oAddmerch.ServerTime = safestring(Now())
        '    oAddmerch.SourceIP = safestring(Request.ServerVariables("REMOTE_ADDR"))
        '    '-----	end server ip, server time, and source ip auditing
        '    viaKlixID = oAddmerch.AddMerchant(MerchantType, password)
        '    If Err.Number <> 0 Then
        '        Msg = Err.Message
        '        Err.Clear()
        '    End If
        '    If viaKlixID <> "" Then
        '        Response.Redirect("adm_addmerchantconfirm.asp?viaKlixID=" & Server.UrlEncode(viaKlixID) & "&TerminalNumber=" & Server.UrlEncode(TID))
        '    Else
        '        If Len(oAddmerch.ErrMsg) > 0 Then
        '            Msg = "New merchant creation failed.<br>" & oAddmerch.ErrMsg
        '        Else
        '            Msg = "New merchant creation failed.<br>Uknown reason."
        '        End If
        '    End If
        '    oAddmerch = Nothing
        'End If

        'End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("/MerchantMngt/merchant_default.aspx")
    End Sub
End Class
